from rest_framework.serializers import ModelSerializer

from areas.models import Area


class AreaSerializer(ModelSerializer):
    """查询所有省份的序列化器"""

    class Meta:
        model = Area
        fields = ('id', 'name')


class SubAreaSerializer(ModelSerializer):
    """ 市，区的序列化器 """
    subs = AreaSerializer(many=True, read_only=True)  # Area模型类中 related_name = subs 的值,相当于之前外键使用的类名小写．set

    class Meta:
        model = Area
        fields = ('id', 'name', 'subs')
